package dbhandler.handler;

import dbhandler.ResultSetHandler;
import dbhandler.Row;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BeanListHandler<T> implements ResultSetHandler<List<T>> {

    private Class<?> type;
    public BeanListHandler(Class<?> type){
        this.type=type;
    }

    public List<T> handler(ResultSet rs) throws SQLException {
        List<T> list=new ArrayList<T>();
        while(rs.next()){
            list.add((T)Row.toBean(rs,type));
        }
        return list;
    }
}
